package com.qys.livesMall.system.controller.sys;


import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.qys.livesMall.common.result.R;
import com.qys.livesMall.system.model.dto.app.ExchangeRateQuery;
import com.qys.livesMall.system.model.entity.H2ExchangeRate;
import com.qys.livesMall.system.service.IH2ExchangeRateService;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import lombok.RequiredArgsConstructor;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

/**
 * <p>
 * 前端控制器
 * </p>
 *
 * @author caoz
 * @since 2023-04-26
 */
@Tag(name = "后台管理-汇率管理")
@RestController
@RequiredArgsConstructor
@RequestMapping("/h2-exchange-rate")
public class H2ExchangeRateController {

    @Autowired
    private IH2ExchangeRateService exchangeRateService;

    @Operation(description = "添加汇率")
    @PostMapping("/add")
    public R<?> add(@RequestBody H2ExchangeRate params) {
        exchangeRateService.add(params);
        return R.ok();
    }

    @Operation(description = "修改汇率")
    @PostMapping("/put")
    public R<?> put(@RequestBody H2ExchangeRate params) {
        exchangeRateService.put(params);
        return R.ok();
    }

    @Operation(description = "通过id查询汇率")
    @PostMapping("/getById/{id}")
    public R<H2ExchangeRate> getById(@PathVariable("id") long id) {
        return R.ok(exchangeRateService.getById(id));
    }

    @Operation(description = "汇率分页查询")
    @PostMapping("/pageList")
    public R<Page<?>> pageList(@RequestBody ExchangeRateQuery query) {
        return R.ok(exchangeRateService.pageList(query));
    }

    @Operation(description = "删除汇率")
    @DeleteMapping("/del/{id}")
    public R<?> del(@PathVariable Integer id) {
        return R.ok(exchangeRateService.removeById(id));
    }
}
